#import "BGWindow.h"
#import <dpsclient/wraps.h>
#import <math.h>

/**
 ** a BGwindow understands the composite operators, lockFocus,
 ** and it knows how to erase itself.  Its designated
 ** initializer is frame: aRect...it will make a
 ** retained window.  
 **/

@implementation BGWindow: Window

- erase ;
{ [contentView lockFocus] ;
  PSsetgray(1.0) ;
  PSsetalpha(1.0) ; // just in case...
  PSrectfill(0.0,0.0,frame.size.width,frame.size.height) ;
  PSsetgray(0.0) ;
  [contentView unlockFocus] ;
  return self ;
}


- erase: (NXRect *) aRect ;
{ [contentView lockFocus] ;
  PSsetgray(1.0) ;
  PSsetalpha(1.0) ; // just in case...
  PSrectfill(aRect->origin.x,aRect->origin.y,
      aRect->size.width,aRect->size.height) ;
  PSsetgray(0.0) ;
  [contentView unlockFocus] ;
  return self ;
}

- composite: (int) op fromRect: (const NXRect *) aRect toPoint: (const NXPoint *) aPnt ;
{ // composite aRect in my coords to currently focused view
  PScomposite(rint(aRect->origin.x),rint(aRect->origin.y),
   aRect->size.width,aRect->size.height,
   [self gState], rint(aPnt->x), rint(aPnt->y), op) ;
  return self ;
}

- composite: (int) op toPoint: (const NXPoint *) aPnt ;
{ // composite my entire frame to aPnt of currently focused view
  PScomposite(0.0,0.0,frame.size.width,frame.size.height,
   [self gState], rint(aPnt->x), rint(aPnt->y), op) ;
  return self ;
}

- composite: (int) op ;
{ // composite to 0,0
  PScomposite(0.0,0.0,frame.size.width,frame.size.height,
   [self gState], 0.0, 0.0, op) ;
  return self ;
}

- frame: (NXRect *) aFrame ;
{ [self 
     initContent: aFrame
     style: NX_PLAINSTYLE
     backing: NX_RETAINED
     buttonMask: 0
     defer: NO] ;
  [self setDynamicDepthLimit: NO] ;
  [self setDepthLimit: NX_TwelveBitRGBDepth] ;
  return self ;
}

- (BOOL) lockFocus ;
{ return [contentView lockFocus] ;
}

- unlockFocus ;
{ return [contentView unlockFocus] ;
}

@end